#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "affichageDyn.h"
  
void pause();  
  
int main(int argc, char *argv[])
{
	SDL_Surface *ecran = NULL, *rectangle = NULL, *rectangle2 = NULL;
	SDL_Surface *rectangle_d = NULL, *rectangle2_d = NULL;
	SDL_Rect position, pos2;


    	ecran = SDL_SetVideoMode(300, 300, 32, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF); // On tente d'ouvrir une fenêtre
    	
    	if (ecran == NULL) { // Si l'ouverture a échoué, on le note et on arrête
        	fprintf(stderr, "Impossible de charger le mode vidéo : %s\n", SDL_GetError());
        	exit(EXIT_FAILURE);
    	}
    	
    	SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 17, 206, 112));
    	
    	//rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, 220, 180, 32, 0, 0, 0, 0);
    	rectangle = SDL_LoadBMP("logoSylverFalcon.bmp");
    	rectangle2 = SDL_CreateRGBSurface(SDL_HWSURFACE, 180, 220, 32, 0, 0, 0, 0);
    	position.x = 0; // Les coordonnées de la surface seront (0, 0)
    	position.y = 0;
    	
    	pos2.x = 200;
    	pos2.y = 0;
    	// Remplissage de la surface avec du blanc
    	//SDL_FillRect(rectangle, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); 
    	
    	SDL_FillRect(rectangle2, NULL, SDL_MapRGB(ecran->format, 0, 255, 255)); 
    	 
    	/****************************Test*************************************/
    	
    	
    	dynInit(rectangle, &rectangle_d);
        dynInit(rectangle2, &rectangle2_d);
    	int continuer = 1;
    	int height;
    	SDL_Event event;
  
    	while (continuer) {
    		height = ecranHeight(ecran);
        	SDL_WaitEvent(&event);
        	switch(event.type) {
            	case SDL_QUIT:
                	continuer = 0;
        	}
       		if(event.type == SDL_VIDEORESIZE) {
         		int newWIDTH, newHIGHT;
         		newWIDTH = event.resize.w; // <- largeur
         		newHIGHT = event.resize.h; // <- hauteur
           		ecran = SDL_SetVideoMode(newWIDTH,newHIGHT, 32, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
           		SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 17, 206, 112));
           		
           		dynSize(rectangle, &rectangle_d, ecran, height, &position);
           		dynSize(rectangle2, &rectangle2_d, ecran, height,  &pos2);
    		}
        
        
       	
        SDL_BlitSurface(rectangle_d, NULL, ecran, &position);
        
        SDL_BlitSurface(rectangle2_d, NULL, ecran, &pos2);
        
        SDL_Flip(ecran); // Mise à jour de l'écran
        	
    	}
    	
    	/************************FinTest**************************/
    	 
  	pause();
  
    	SDL_Quit(); // Arrêt de la SDL (libération de la mémoire).
  
   	return 0;
}

void pause() {
	
}
